package main

import "fmt"

func doAstIsCreate() {
	writer.Write("package ast")
	writer.WriteLine()

	writeUtilCreate()
}

func container(names []string, items... string) bool {
	for _, name := range names {
		for _, item := range items {
			if name == item {
				return true
			}
		}
	}
	return false
}

func isNode (names []string) bool {
	return container(names, "node")
}

func isDecl (names []string) bool {
	return container(names, "decl", "class")
}

func isExpr (names []string) bool {
	return container(names, "expr")
}

func isStmt (names []string) bool {
	return container(names, "stmt")
}

func isType (names []string) bool {
	return container(names, "type_")
}

func isAst(names []string) bool {
	return isNode(names) ||
		isDecl(names) ||
		isExpr(names) ||
		isStmt(names) ||
		isType(names)
}

func isPublic(name string) bool {
	if len(name) < 0 {
		return false
	}

	return name[0] >= 'A' && name[0] <= 'Z'
}



var exclude = []string{
	"NodeFlags",
	"ModifierFlags",
	"CommentRange",
	"TextRange",
	"ScriptKind",
	"Expression",
	"Node",
	"Declaration",
	"Type",
	"Statement",
	"ScriptTarget",
	"PackageTree",
	"List",
	"NodeList",
	"DeclarationList",
	"StatementList",
	"ExpressionList",
	"TypeList",
	"Signature",
	"FunctionLike",
	"ObjectLike",
	"VariableLike",
	"DocumentTag",
	"Document",
	"DocumentContainer",
	"Status",

}

func writeUtilCreate(){
	for _, info1 := range infos {

		if !isPublic(info1.name) {
			continue
		}

		if container(exclude, info1.name) {
			continue
		}
		//
		//if !isAst(info1.types) {
		//	continue
		//}


		writer.Write(fmt.Sprintf(
			`
func Is%s(node Node) bool {
	_, ok := node.(*%s)
	return ok
}
`, info1.name, info1.name))
	}

}